package com.workingpub.commons.resource.internal;

import java.util.Map;

import com.workingpub.commons.resource.CommonConfig;
import com.workingpub.commons.utils.jmx.MBeanSuport;

/**
 * 
 * @author taoping
 *
 */
public class ConfigAdmin extends MBeanSuport implements ConfigAdminMXBean {
	public static final String MBEAN_NAME = "dapp.commons:type=ConfigAdmin";

	@Override
	public String getProperty(String key) {
		CommonConfig commonConfig = Activator.getInstance().getService(CommonConfig.class);
		return null == commonConfig ? null : commonConfig.getProperty(key, null);
	}

	@Override
	public Map<String, String> listConfigs() {
		CommonConfig commonConfig = Activator.getInstance().getService(CommonConfig.class);
		return null == commonConfig ? null : commonConfig.getProperties();
	}

	@Override
	public void reload() {
		CommonConfig commonConfig = Activator.getInstance().getService(CommonConfig.class);
		if (null != commonConfig) {
			commonConfig.reload();
		}
	}

	@Override
	protected String getDefaultObjectName() {
		return MBEAN_NAME;
	}

}
